package com.sc.nft.admin.controller;


import cn.hutool.core.bean.BeanUtil;
import com.sc.nft.admin.request.*;
import com.sc.nft.annotation.SysMemberLogin;
import com.sc.nft.entity.SalvageEventsInfo;
import com.sc.nft.entity.vo.AdminSalvageEventsPageVO;
import com.sc.nft.entity.vo.salvageEvents.AdminPageSalvageEventsRecordsVO;
import com.sc.nft.entity.vo.salvageEvents.GetAdminDetailsByIdVO;
import com.sc.nft.entity.vo.salvageEvents.SalvageRewardsVO;
import com.sc.nft.service.AdminSalvageEventsDetailsService;
import com.sc.nft.sup.PageResult;
import com.sc.nft.sup.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

@Slf4j
@RequiredArgsConstructor
@RestController
@RequestMapping("/admin/salvage/events")
@Api(tags = "后台分解活动")
public class AdminSalvageEventsController {


    private final AdminSalvageEventsDetailsService adminSalvageEventsDetailsService;


    @PostMapping(value = "/getPage", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "分页获取分页活动列表", notes = "分页获取分页活动列表", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public PageResult<AdminSalvageEventsPageVO> getPage(@Valid @RequestBody GetSalvageEventsPageRequest request) {
        return PageResult.success(adminSalvageEventsDetailsService.getAdminSalvageEventsPage(request.getEventsName(), request.getPageNo(), request.getPageSize()));
    }

    @PostMapping(value = "/add", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "添加分解活动", notes = "添加分解活动", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result adminAddSalvageEvents(@Valid @RequestBody AdminAddSalvageEventsRequest request) {
        SalvageEventsInfo salvageEventsInfo = BeanUtil.copyProperties(request, SalvageEventsInfo.class);
        adminSalvageEventsDetailsService.adminAddSalvageEvents(salvageEventsInfo, request.getCollectionList());
        return Result.success();
    }


    @PostMapping(value = "/getDetailsById", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "添加分解详情", notes = "添加分解详情", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result<GetAdminDetailsByIdVO> getAdminDetailsById(@Valid @RequestBody IdRequest request) {
        return Result.success(adminSalvageEventsDetailsService.getAdminDetailsById(request.getId()));
    }


    @PostMapping(value = "/updateIsListing", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "修改上下架", notes = "修改上下架", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result updateIsListing(@Valid @RequestBody UpdateIsListing request) {
        adminSalvageEventsDetailsService.updateIsListing(request.getId(), request.getIsListing());
        return Result.success();
    }


    @PostMapping(value = "/updateSort", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "修改排序", notes = "修改上下架", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result updateSort(@Valid @RequestBody UpdateRankingBoardSortRequest request) {
        adminSalvageEventsDetailsService.updateSort(request.getId(), request.getSort());
        return Result.success();
    }

    @PostMapping(value = "/delById", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "删除分解活动", notes = "删除分解活动", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result delById(@Valid @RequestBody IdRequest request) {
        adminSalvageEventsDetailsService.delById(request.getId());
        return Result.success();
    }


    @PostMapping(value = "/updateInfoById", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "修改分解活动基础信息", notes = "修改分解活动基础信息", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result updateInfoById(@Valid @RequestBody UpdateSalvageEventsInfoRequest request) {
        adminSalvageEventsDetailsService.updateInfoById(request.getId(), request.getCoverImage(), request.getRegularImage(), request.getSumCount(), request.getUserCount(), request.getShowSalvagePrefecture(), request.getConsumeConsensus());
        return Result.success();
    }


    @PostMapping(value = "/getPageSalvageEventsRecords", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "获取分解记录", notes = "获取分解记录", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public PageResult<AdminPageSalvageEventsRecordsVO> getPageSalvageEventsRecords(@Valid @RequestBody PageSalvageEventsRecordsRequest request) {
        return PageResult.success(adminSalvageEventsDetailsService.gtPageSalvageEventsRecords(request.getUserTel(), request.getEventsName(), request.getPageNo(), request.getPageSize()));
    }

    @PostMapping(value = "/getRewards", produces = MediaType.APPLICATION_JSON_VALUE)
    @ApiOperation(value = "获取分解活动奖励", notes = "获取分解活动奖励", httpMethod = "POST", produces = MediaType.APPLICATION_JSON_VALUE)
    @SysMemberLogin
    public Result<SalvageRewardsVO> getRewards(@Valid @RequestBody SalvageRewardsRequest request) {
        return Result.success(adminSalvageEventsDetailsService.getRewards(request.getId(), request.getCollectionId()));
    }


}
